package com.itgaoshu.hospitalproject.mapper;

import com.itgaoshu.hospitalproject.bean.Lrecord;
import com.itgaoshu.hospitalproject.bean.Pay;
import com.itgaoshu.hospitalproject.bean.Register;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface LPayMapper {
    //查询所有的缴费表根据患者的id来查询
    @Select("select p.payid,r.registerid,r.userName,p.money,p.payDate from pay p,register r where r.registerid=p.registerid and r.registerid=#{registerid}")
    List<Pay> selPays(Register register);
    //添加预交金的操作
    @Update("update register set money=money+#{money} where registerid=#{registerid}")
    int updatePay(Register register);
    //添加记录的操作
    @Insert("insert into pay values(null,#{registerid},#{money},now())")
    int addPay(Register register);

    //查询该患者还剩余多少钱
    //函数 IFNULL() 函数用于判断第一个表达式是否为 NULL,
    // 如果为 NULL 则返回第二个参数的值,如果不为 NULL 则返回第一个参数的值。
    @Select("select (((TO_DAYS(NOW())-TO_DAYS(ifnull(r.zhuan,r.registerDate)))*p.price)+ifnull(sum(h.repicetotal),0))*(1-(cast(replace(r.discount,'%','') as decimal(18,2))/100))+IFNULL(r.price,0) repicetotal from (select price from bed where bedid=(select bednum from register where registerid=#{registerid})) p,register r left join hospitalprice h on h.registerId=r.registerid where r.registerid=#{registerid}")
    List<Lrecord> selSurplus(Lrecord lrecord);



}
